<?php

require_once 'common/common.inc.php';

$location_code = $_REQUEST["location_code"];
$service_code = "KNIPPEN";

$sql = "";
$sql .= "SELECT ID, NAME, START, END, COMPANY_CODE, DATE_FORMAT(START,'%Y-%m-%d') START_SHORT_ISO ";
$sql .= "FROM SCHEDULES ";
$sql .= "WHERE COMPANY_CODE = '$company_code' ";
$sql .= "AND LOCATION_CODE = '$location_code' ";
$sql .= "AND SERVICE_CODE = '$service_code' ";
//echo $sql;
conn();
$result = mysql_query($sql);
if (!$result) {die('Could not exec query: ' . mysql_error());}
$numRows = mysql_num_rows($result);
close();

$counter = 0;
$json = "";
$json .= "{\n";
if ($numRows > 0) {
  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      $json .= "\"$counter\"";
      $json .= ":";
      $json .= "\"".$row["START_SHORT_ISO"]."\"";
      if ($counter+1 < $numRows) {
        $json .= ",";
      } 
      $json .= "\n";
      $counter = $counter + 1;
  }
  mysql_data_seek($result, 0); 
} 
$json .= "}\n";

echo $_GET['jsoncallback'].'('.$json.')';

//$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
//echo $_GET['jsoncallback'].'('.json_encode($arr).')';
?>
